package jiekoudeshiyongshili;

import sortcomparator.Second;

import java.util.Arrays;

public class first {

    public static void My_Arrays_sort(One[] one) {
        for (int i = 0; i < one.length; i++) {
            for (int j = 0; j < one.length - i - 1; j++) {
                if (one[j].compareTo(one[j + 1]) > 0) {
                    One tmp = one[j];
                    one[j] = one[j + 1];
                    one[j + 1] = tmp;
                }
            }
        }
    }

    public static void Swap_(Swap v1, Swap v2) {
        int tmp = v1.a;
        v1.a = v2.a;
        v2.a = tmp;
    }

    public static void main(String[] args)
            throws CloneNotSupportedException {
        //clone
        One one = new One("haha",12);
        One two = (One)one.clone();
        two.age = 10;
        two.name = "pp";
        System.out.println(two.toString());
        One.inner_one hh = two.new inner_one();
        One.inner_one hhh = one.new inner_one();
        hh.aa = 9;
        System.out.println("dddddd");
        //深拷贝
        one.a.setA(10);
        System.out.println(one.a.a);
        two.a.a = 23;
        System.out.println(two.a.a);
        System.out.println("dddddd");
        System.out.println(one.toString());
    }
    //交换俩个数
    public static void maibbn(String[] args) {
        Swap value1 = new Swap();
        Swap value2 = new Swap();
        value1.a = 10;
        value2.a = 100;
        System.out.println(value1.a+" "+ value2.a);
        Swap_(value1,value2);
        System.out.println(value1.a+" "+ value2.a);

    }
    public static void mainaa(String[] args) {
        One[] one = new One[3];
        one[0] = new One("zhagnsan", 22);
        one[1] = new One("lisi", 11);
        one[2] = new One("wanger", 23);
        Second second = new Second();
        System.out.println(second.reversed());
        System.out.println(Arrays.toString(one));
        Arrays.sort(one,second.reversed());
        System.out.println(Arrays.toString(one));
        Arrays.sort(one, second);
        System.out.println(Arrays.toString(one));
        //second.thenComparing(second,)
    }
    //用sort给排序
    public static void mainm(String[] args) {
        One[] one = new One[3];
        one[0] = new One("zhagnsan", 22);
        one[1] = new One("lisi", 11);
        one[2] = new One("wanger", 23);
        System.out.println("排序前 " + Arrays.toString(one));
        //这里排序的顺序依据是你自己在这个类中写的comparable方法
        //且如果要对自定义类型排序这个类必须要实现Comparable接口，且要重写里面的compareTo方法
        Second second = new Second();
        Arrays.sort(one, second);//可以传入第二个使用comparator接口的对象，在排序是会调用第二个对象中的compare方法
        System.out.println(second.equals(one));
//        My_Arrays_sort(one);
        System.out.println("排序后 " + Arrays.toString(one));

    }

    public static void mainn(String[] args) {
        One one = new One("zhangsan", 20);
        One two = new One("lisi", 15);
//        System.out.println(one.compareTo(two));
    }

}
